package com.test.mytest.socket;

import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class ClientServer {
	public static void main(String[] args) {
		try {
			URL url = new URL("http://127.0.0.1:9999/test/?type=123");
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			con.setRequestMethod("POST");
			con.setRequestProperty("Content-Type", "application/octet-stream"); 
			con.setDoOutput(true);
			con.setDoInput(true);
			con.setUseCaches(false);  
//			con.setRequestProperty("Content-type","application/x-java-serialized-object");  
			con.connect();  

			OutputStream outputStream = con.getOutputStream();
			InputStream inputStream = con.getInputStream();
			ObjectInputStream ois = new ObjectInputStream(inputStream); 
			Object o;
			while(true){
				if (inputStream.available()>0){
					o=ois.readObject();
					System.out.println("while==="+o);
					ObjectOutputStream oos=new ObjectOutputStream(outputStream);
					oos.writeObject(o);
					oos.flush();
				}
				Thread.sleep(50);
			}
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
